<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
</head>

<body>

    <p>回调函数等待 3 秒后执行。</p>
    <p id="demo1"></p>
    <p id="demo2"></p>
    <script>
        setTimeout(function () {
            document.getElementById("demo1").innerHTML = "RUNOOB-1!";  // 三秒后子线程执行
        }, 3000);
        document.getElementById("demo2").innerHTML = "RUNOOB-2!";      // 主线程先执行
    </script>

<!-- 异步请求 -->
    <p><strong>以下内容是通过异步请求获取的：</strong></p>
    <p id="demo"></p>
    <script>
        var xhr = new XMLHttpRequest();

        xhr.onload = function () {
            // 输出接收到的文字数据
            document.getElementById("demo").innerHTML = xhr.responseText;
        }

        xhr.onerror = function () {
            console.log(xhr)
            document.getElementById("demo").innerHTML = "请求出错";
        }

        // 发送异步 GET 请求
        xhr.open("GET", "https://v1.jinrishici.com/all.json", true);
        xhr.send();
    </script>
</body>

</html>